package algorithm.leetcode;

/**
 * @program: util
 * @description: 翻转整数
 * @author: zhouliangliang
 * @create: 2021-03-30 11:40
 **/
public class ReverseInt {

    /**
     * 翻转整数
     * @param num
     */
    public int reverseInt(int num) {
        int reverse = 0;
        while(num != 0) {
            if(reverse > Integer.MAX_VALUE /10 || reverse < Integer.MIN_VALUE / 10) {
                return 0;
            }
            int value = num % 10;
            num = num /10;
            reverse = reverse * 10 + value;
        }
        return reverse;
    }


    public static void main(String[] args) {
        new ReverseInt().reverseInt(-123);
    }
}
